package com.party.core.service.member.impl;

import com.google.common.base.Strings;
import com.party.common.paging.Page;
import com.party.core.dao.read.member.ThirdMemberReadDao;
import com.party.core.dao.write.member.ThirdMemberWriteDao;
import com.party.core.model.BaseModel;
import com.party.core.model.member.ThirdMember;
import com.party.core.service.member.IThirdMemberService;
import org.apache.commons.collections.CollectionUtils;
import org.apache.commons.collections.map.HashedMap;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Collections;
import java.util.Date;
import java.util.List;
import java.util.Set;

/**
 * @author: Administrator.
 * @Description: 第三方用户
 * @Date:Created in 2017/10/18 0018 下午 16:48.
 */
@Service
public class ThirdMemberService implements IThirdMemberService {
    @Autowired
    private ThirdMemberReadDao thirdMemberReadDao;
    @Autowired
    private ThirdMemberWriteDao thirdMemberWriteDao;

    @Override
    public String insert(ThirdMember t) {
        BaseModel.preInsert(t);
        boolean result = thirdMemberWriteDao.insert(t);
        if (result) {
            return t.getId();
        }
        return null;
    }

    @Override
    public boolean update(ThirdMember t) {
        t.setUpdateDate(new Date());
        return thirdMemberWriteDao.update(t);
    }

    @Override
    public boolean deleteLogic(String id) {
        if (Strings.isNullOrEmpty(id)) {
            return false;
        }
        return thirdMemberWriteDao.deleteLogic(id);
    }

    @Override
    public boolean delete(String id) {
        if (Strings.isNullOrEmpty(id)) {
            return false;
        }
        return thirdMemberWriteDao.delete(id);
    }

    @Override
    public boolean batchDeleteLogic(Set<String> ids) {
        if (CollectionUtils.isEmpty(ids)) {
            return false;
        }
        return thirdMemberWriteDao.batchDeleteLogic(ids);
    }

    @Override
    public boolean batchDelete(Set<String> ids) {
        if (CollectionUtils.isEmpty(ids)) {
            return false;
        }
        return thirdMemberWriteDao.batchDelete(ids);
    }

    @Override
    public ThirdMember get(String id) {
        return thirdMemberReadDao.get(id);
    }

    @Override
    public List<ThirdMember> listPage(ThirdMember t, Page page) {
        return thirdMemberReadDao.listPage(t, page);
    }

    @Override
    public List<ThirdMember> list(ThirdMember t) {
        return thirdMemberReadDao.listPage(t, null);
    }

    @Override
    public List<ThirdMember> batchList(Set<String> ids, ThirdMember t, Page page) {
        if (CollectionUtils.isEmpty(ids)) {
            return Collections.EMPTY_LIST;
        }
        return thirdMemberReadDao.batchList(ids, new HashedMap(), page);
    }

    @Override
    public ThirdMember getUnique(ThirdMember thirdMember) {
        return thirdMemberReadDao.getUnique(thirdMember);
    }

    @Override
    public ThirdMember findByTargetId(String targetId) {
        ThirdMember thirdMember = new ThirdMember();
        thirdMember.setTargetId(targetId);
        return getUnique(thirdMember);
    }

    @Override
    public List<String> allURI() {
        return thirdMemberReadDao.allURI();
    }

    @Override
    public List<String> allAccount() {
        return thirdMemberReadDao.allAccount();
    }

    @Override
    public void deleteByTargetId(String targetId) {
        thirdMemberWriteDao.deleteByTargetId(targetId);
    }
}
